﻿using System;
using System.Collections.Generic;
using System.Text;

using YouHP.Utility;
using YouHP.BLL;
using YouHP.Model;

namespace YouHP.Pages.User
{
    public class Activate : YouHP.Pages.BasePage
    {
        protected override void ShowPage()
        {
            
            this.AddLinkCss("/support/Alpha/css/reg.css");

            HandleCommon();
            string encodedUserName = RequestTools.GetQueryString("userName");
            encodedUserName = encodedUserName.Replace(' ', '+');
            string activeCode = RequestTools.GetQueryString("activeCode");
            string userName = Encoding.UTF8.GetString(Convert.FromBase64String(encodedUserName));            
            try
            {
                if (UserBLL.Instance.ActiveUserByActiveCode(userName, activeCode))
                {
                    //激活成功，并提示信息
                    this.AddMsgLine("您已成功激活账号："+ userName + "，页面将自动跳转至登录页面！");
                    UserInfo UserData_ = new UserInfo();
                    UserData_ = UserBLL.Instance.GetUserInfo(userName);
                    int expireTime = RequestTools.GetFormInt("expiretime", -1);
                    CookiesTools.WriteUserCookie(UserData_.Id.ToString(), UserData_.UserName, expireTime);
                    //CookiesTools.WriteUserNameCookie(UserData_.UserName);
                    //UserData = UserData_;
                    //this.SetMetaRefresh(3, "../User/login.aspx");
                    base.ShowPage();
                }
                else
                {
                    //激活失败，并提示信息
                    this.AddMsgLine("对不起，您的账号：" + userName + "激活失败，请再次确认！");
                    ErrorCount = 1;
                }
            }
            catch
            {

            }
        }
        protected void HandleCommon()
        {
            this.AddLocation("用户激活", "/User/Activate.aspx");
        }
    }
}
